//
//  SideMenuViewController.m
//  news_ios_app
//
//  Created by apple on 16/3/19.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "SideMenuViewController.h"

#define headHeight  180

#define headImageHeight   80

#define labelHeight 30 * kPROPORTION

#define labelWidth  BOUNDWIDTH * 0.6

#define cellHeight  100 * kPROPORTION

#define cellInterval ((BOUNDWIDTH * 0.8) - (cellHeight * 2))/3


@interface SideMenuViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (strong,nonatomic) UIImageView *headImageView;
@property (strong,nonatomic) UIView *headImageBackView;
@property (strong,nonatomic) UILabel *userNameLab;
@property (strong,nonatomic) UICollectionView *itemCollection;
@end

@implementation SideMenuViewController

-(void)initSubView
{
    [self initHeadImageBackView];
    [self initHeadImageView];
    [self initUserNameLab];
    [self initItemCollection];
}

-(void)initHeadImageBackView
{
    _headImageBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, BOUNDWIDTH * swipProportion, headHeight * kPROPORTION)];
    _headImageBackView.backgroundColor = RGBCOLOR(66, 168, 235);
    [self.view addSubview:_headImageBackView];
}

-(void)initHeadImageView
{
    _headImageView = [[UIImageView alloc]init];
    _headImageView.frame = CGRectMake((BOUNDWIDTH * swipProportion - headImageHeight * kPROPORTION)/2, (headHeight*kPROPORTION - headImageHeight * kPROPORTION)/2-(15 * kPROPORTION) , headImageHeight * kPROPORTION, headImageHeight * kPROPORTION);
    _headImageView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_headImageView];
}

-(void)initItemCollection
{
    UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc]init];
    [flowLayOut setScrollDirection:UICollectionViewScrollDirectionVertical];
    flowLayOut.itemSize = CGSizeMake(100 * kPROPORTION, 100 * kPROPORTION);
    flowLayOut.minimumInteritemSpacing = 8;
    flowLayOut.minimumLineSpacing = 20;

    _itemCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, headHeight * kPROPORTION, BOUNDWIDTH * swipProportion, BOUNDHEIGHT - headHeight * kPROPORTION) collectionViewLayout:flowLayOut];
    _itemCollection.backgroundColor = [UIColor whiteColor];
    
    [_itemCollection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"CollectionViewIdentifier"];
    _itemCollection.delegate = self;
    _itemCollection.dataSource = self;
    [self.view addSubview:_itemCollection];
}

-(void)initUserNameLab
{
    _userNameLab = [[UILabel alloc]init];
    _userNameLab.frame = CGRectMake((BOUNDWIDTH * swipProportion - labelWidth)/2, OriginY(_headImageView) + 15 * kPROPORTION, labelWidth, labelHeight);
    _userNameLab.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_userNameLab];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initSubView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - collectionDatasource

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {

    return UIEdgeInsetsMake(cellInterval, cellInterval, 0, cellInterval);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    static NSString *cellIdentifier = @"cellIdentifier";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewIdentifier" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor grayColor];
    return cell;
}
@end
